package com.qymerge.manage.base.controller;

import com.google.common.reflect.TypeToken;
import com.qymerge.manage.base.ro.MetaAccountViewRO;
import com.qymerge.manage.base.service.IMetaAccountViewService;
import com.qymerge.manage.core.bean.DataTableRO;
import com.qymerge.manage.core.bean.PageRequest;
import com.qymerge.manage.core.bean.ParamCommon;
import com.qymerge.manage.core.bean.ParamValue;
import com.qymerge.manage.core.constant.ParamKey;
import com.qymerge.manage.core.controller.BaseController;
import com.qymerge.manage.core.utils.GsonUtil;
import com.qymerge.manage.core.utils.PrintCodeUtils;
import com.qymerge.manage.core.utils.RequestCheckUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Title: </p>
 * <p>Description: 科目</p>
 *
 * @author Xiao
 * @date 2025/4/29 17:18
 * @version 1.0.0
 */
@Controller
@RequestMapping(value = "base/accountView")
public class IMetaAccountViewManageController extends BaseController {

    @Autowired
    private IMetaAccountViewService metaAccountViewService;

    /**
     * 列表
     *
     * @param parameters
     * @param callback
     */
    @RequestMapping("list")
    public void list(HttpServletRequest request, HttpServletResponse response,

                     @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                     @RequestParam(defaultValue = ParamKey.In.empty) String callback) {
        ParamValue<MetaAccountViewRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<MetaAccountViewRO>>() {
        }.getType());
        ParamCommon common = paramValue.getCommon();
        MetaAccountViewRO ro = paramValue.getData();

        DataTableRO data = metaAccountViewService.list(ro, new PageRequest(common.getPage(), common.getSize()));
        PrintCodeUtils.printSuccess(response, data.build(), callback);
    }

    /**
     * 详情
     *
     * @param request
     * @param response
     * @param callback
     * @throws Exception
     */
    @RequestMapping("detail")
    public void detail(HttpServletRequest request, HttpServletResponse response,

                       @RequestParam(defaultValue = ParamKey.In.dlt_parameters) String parameters,
                       @RequestParam(defaultValue = ParamKey.In.empty) String callback) throws Exception {

        ParamValue<MetaAccountViewRO> paramValue = GsonUtil.json2T(parameters, new TypeToken<ParamValue<MetaAccountViewRO>>() {
        }.getType());
        MetaAccountViewRO ro = paramValue.getData();

        MetaAccountViewRO resultRO = metaAccountViewService.detail(ro.getCode());

        PrintCodeUtils.printSuccess(response, resultRO, callback);
    }


}
